﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChinaDynastyTours.Controls;

namespace ChinaDynastyTours.Views
{
    public partial class TourGroupInfoControl : UserControl
    {
        public bool _InitTourGroupID { 
            set
            {
                if (value)
                {
                    //初始化团下拉列表
                    DataSet ds = TeamGroupCtrl.GetAllIDForTeamGroup();
                    if (ds.Tables.Count > 0)
                        foreach (DataRow dr in ds.Tables[0].Rows)
                            btnTeamGroupID.Properties.Items.Add(dr["TourGroupID"].ToString().Trim());

                    //InitGui();
                }
            }
        }
        
        public string _TourGroupID
        {
            get
            {
                if (_TourGroupDataTable==null || BindingContext[_TourGroupDataTable].Position == -1) 
                    return "";
                else
                {
                    DataRowView drv = (BindingContext[_TourGroupDataTable].Current as DataRowView);
                    return drv["TourgroupID"].ToString();
                }
            }

        }
        public string _TourGroupName
        {
            get
            {
                if (_TourGroupDataTable == null || BindingContext[_TourGroupDataTable].Position == -1)
                    return "";
                else
                {
                    DataRowView drv = (BindingContext[_TourGroupDataTable].Current as DataRowView);
                    return drv["TourgroupName"].ToString();
                }
            }

        }
        public string _TourGroupState { 
            get{
                if (_TourGroupDataTable == null || BindingContext[_TourGroupDataTable].Position == -1)
                    return "";
                else
                {
                    DataRowView drv = (BindingContext[_TourGroupDataTable].Current as DataRowView);
                    return drv["TourgroupState"].ToString();
                }
            }
        }
        
        public int _CustomerID
        {
            get
            {
                if (_TourGroupDataTable == null || BindingContext[_TourGroupDataTable].Position == -1)
                    return -1;
                else
                {
                    DataRowView drv = (BindingContext[_TourGroupDataTable].Current as DataRowView);
                    return int.Parse(drv["CustomerID"].ToString());
                }
            }
        }
        public string _CustomerName
        {
            get
            {
                if (_TourGroupDataTable == null || BindingContext[_TourGroupDataTable].Position == -1)
                    return "";
                else
                {
                    DataRowView drv = (BindingContext[_TourGroupDataTable].Current as DataRowView);
                    return drv["CustomerName"].ToString();
                }
            }
        }

        private DataTable _TourGroupDataTable { get; set; }

        public TourGroupInfoControl()
        {
            InitializeComponent();

        }

                //初始化界面内容
        private void InitGui()
        {
            _TourGroupDataTable = TeamGroupCtrl.GetTeamGroupRowData(btnTeamGroupID.Text);

            tbCountry.DataBindings.Clear();
            lblCountryCode.DataBindings.Clear();
            tbStartDate.DataBindings.Clear();
            tbEndDate.DataBindings.Clear();
            tbNightNum.DataBindings.Clear();
            tbAdultNum.DataBindings.Clear();
            tbChildNum.DataBindings.Clear();
            tbTourgroupName.DataBindings.Clear();
            cbGuesttype.DataBindings.Clear();
            cbServicetype.DataBindings.Clear();
            cbTourgrouptype.DataBindings.Clear();
            tbAccompanyNum.DataBindings.Clear();
            tbCustomerCode.DataBindings.Clear();
            lblCustomerName.DataBindings.Clear();
            cbOwnerA.DataBindings.Clear();
            cbOwnerB.DataBindings.Clear();
            ckHasGuide.DataBindings.Clear();
            tbBuildGroupDate.DataBindings.Clear();


            tbCountry.DataBindings.Add("EditValue", _TourGroupDataTable, "Country");
            lblCountryCode.DataBindings.Add("Text", _TourGroupDataTable, "CountryCode");
            tbStartDate.DataBindings.Add("EditValue", _TourGroupDataTable, "StartDate");
            tbEndDate.DataBindings.Add("EditValue", _TourGroupDataTable, "EndDate");
            tbNightNum.DataBindings.Add("EditValue", _TourGroupDataTable, "StayOver");
            tbAdultNum.DataBindings.Add("EditValue", _TourGroupDataTable, "AdultNum");
            tbChildNum.DataBindings.Add("EditValue", _TourGroupDataTable, "ChildNum");
            tbTourgroupName.DataBindings.Add("EditValue", _TourGroupDataTable, "TourgroupName");
            cbGuesttype.DataBindings.Add("EditValue", _TourGroupDataTable, "Guesttype");
            cbServicetype.DataBindings.Add("EditValue", _TourGroupDataTable, "Servicetype");
            cbTourgrouptype.DataBindings.Add("EditValue", _TourGroupDataTable, "Tourgrouptype");
            tbAccompanyNum.DataBindings.Add("EditValue", _TourGroupDataTable, "AccompanyNum");
            tbCustomerCode.DataBindings.Add("EditValue", _TourGroupDataTable, "CustomerCode");
            lblCustomerName.DataBindings.Add("Text", _TourGroupDataTable, "CustomerName");
            cbOwnerA.DataBindings.Add("EditValue", _TourGroupDataTable, "OwnerA");
            cbOwnerB.DataBindings.Add("EditValue", _TourGroupDataTable, "OwnerB");
            ckHasGuide.DataBindings.Add("Checked", _TourGroupDataTable, "HasGuide");
            tbBuildGroupDate.DataBindings.Add("EditValue", _TourGroupDataTable, "BuildGroupDate");
        }

        private void btnTeamGroupID_TextChanged(object sender, EventArgs e)
        {
            InitGui();
        } 
    }
}
